package dao;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class CreateTableUser {
    public static void main(String[] args) throws Exception {
        Connection connection = null;
        try{
            String driver = "com.mysql.jdbc.Driver";
            String url = "jdbc:mysql://localhost/production_eshop";
            String user = "root";
            String password = "2479";
            
            String createUser = "CREATE TABLE User ("
                    + "id INT AUTO_INCREMENT, "
                    + "login VARCHAR(30),"
                    + "email VARCHAR(30),"
                    + "primary key (id))";
            String insertUser = "INSERT INTO User (id, login, email) VALUES (1, 'Sara', 'sara@i.ua')";
            
            Class.forName(driver);
            connection = DriverManager.getConnection(url, user, password);
            
            Statement statement = connection.createStatement();
            statement.executeUpdate("DROP TABLE IF EXISTS User");
            statement.executeUpdate(createUser);
        } catch (SQLException ex){
            ex.printStackTrace();
        }
    }
}
